package de.iritgo.skillfull.entity.command;

import de.iritgo.skillfull.component.visitor.PositionVisitor;
import de.iritgo.skillfull.entity.Command;
import de.iritgo.skillfull.entity.Entity;

public class SetPositionCommand implements Command 
{
	private Entity entity;
	private int x,y;
	private boolean done;
	private PositionVisitor positionVisitor;
	private boolean relative; 
	
	public SetPositionCommand (Entity entity, int x, int y, boolean relative)
	{
		this.relative = relative;
		this.entity = entity;
		done = false;
		this.x = x;
		this.y = y;
		this.positionVisitor = new PositionVisitor (x,y, relative);
		if (!relative)
			entity.setPosition(x, y);
	}

	public String getName ()
	{
		return "Position"; 
	}

	@Override
	public boolean canPerform () 
	{
		return true;
	}

	@Override
	public void perform (int delta) 
	{
		entity.accept (positionVisitor);
		done = true;
	}
	
	public void stop() 
	{
	}
	
	public Command getUndoCommand () 
	{
		return null;
	}

	@Override
	public boolean isDone () 
	{
		return done;
	}
}
